package sizeyunsuan;

import java.text.NumberFormat;
import java.util.*;
public class Practice {
    protected NumberFormat nf = NumberFormat.getPercentInstance();
    Random ran = new Random();
    private String sym, Ti = "";
    protected int Tinum = 0;
    protected int trues;;
    protected List<String> list;
    protected List<String> list1;
    protected List<String> list2;
    Original ori = new Original();
    Counts count = new Counts();

    public Practice() {
        list = new ArrayList<String>();
        list1 = new ArrayList<String>();
        list2 = new ArrayList<String>();
    }

    public void Ti(int number, int many) {
        many = TiclassC(many);
        for (int j = 0; j < number; j++) {
            String ti = "";
            for (int i = 0; i < many; i++) {
                int A = ran.nextInt(8) + 1;
                int D = ran.nextInt(8) + 1;
                int B = ran.nextInt(5);
                int C = ran.nextInt(5);
                RationalNumber si = new RationalNumber(A, D);
                if (parity(i)) {
                    if (list1.indexOf("( ") == -1)
                        list1.add(getSym() + " ");
                    else if (list1.size() - list1.lastIndexOf("( ") > 4) {
                        if (list1.lastIndexOf(") ") - list1.lastIndexOf("( ") < 0 && B == 0) {
                            list1.add(") ");
                            list1.add(getSym() + " ");
                        } else list1.add(getSym() + " ");
                    } else list1.add(getSym() + " ");
                } else if (i == many - 1) {
                    if (list1.lastIndexOf("( ") - list1.lastIndexOf(") ") > 0) {
                        if (C == 0) {
                            list1.add(si.toString() + " ");
                            list1.add(") ");
                        } else {
                            list1.add(A + " ");
                            list1.add(") ");
                        }
                    } else if (C != 0)
                        list1.add(A + " ");
                    else list1.add(si.toString() + " ");
                } else if (i == 0) {
                    if (C != 0)
                        list1.add(A + " ");
                    else list1.add(si.toString() + " ");
                } else if (list1.lastIndexOf(") ") != -1) {
                    if (list1.lastIndexOf(") ") - list1.lastIndexOf("( ") > 0 && B == 0) {
                        list1.add("( ");
                        if (C != 0)
                            list1.add(A + " ");
                        else list1.add(si.toString() + " ");
                    } else if (C != 0)
                        list1.add(A + " ");
                    else list1.add(si.toString() + " ");
                } else if (list1.indexOf("( ") == -1 && B == 0) {
                    list1.add("( ");
                    if (C != 0)
                        list1.add(A + " ");
                    else list1.add(si.toString() + " ");
                } else if (C != 0)
                    list1.add(A + " ");
                else list1.add(si.toString() + " ");
            }
            for (String i : list1)
                ti += i;
            list1.clear();
            ori.evaluate(ti);
            String restrult = count.evaluate(ori.getMessage());
            if (list2.indexOf(restrult) >= 0)
                j--;
            else {
                list2.add(restrult);
                list.add(ti);
            }
        }
    }

    public String getSym() {
        int A = ran.nextInt(4);
        switch (A) {
            case 0:
                sym = "+";
                break;
            case 1:
                sym = "-";
                break;
            case 2:
                sym = "*";
                break;
            case 3:
                sym = "/";
                break;
        }
        return sym;
    }

    public boolean parity(int num) {
        if (num % 2 == 1)
            return true;
        else
            return false;
    }

    public int TiclassC(int many) {
        Scanner scan = new Scanner(System.in);
        int A = 1;
        if (many > 0)
            for (int i = 0; i < many; i++)
                A += 2;
        return A;
    }

}